#pragma once

// 设置一些通用函数的头文件
#include <iostream>
#include <vector>
#include <fstream>
#include <string>
#include <boost/algorithm/string.hpp>

#include "cppjieba/Jieba.hpp"

namespace util
{

    // 通过文件路径读取文件，将读取到的文件内容放到out中
    bool ReadFile(const std::string file_name, std::string *out)
    {
        std::ifstream ifs(file_name, std::ifstream::in);

        if (ifs.is_open() == false)
        {
            std::cout << file_name << " open error" << std::endl;
            return false;
        }

        std::string line;
        while (std::getline(ifs, line))
        {
            *out += line;
        }

        ifs.close();
        return true;
    }

    class StringUtil
    {
    public:
        static void Split(const std::string line, std::vector<std::string> *results, const std::string sep)
        {
            boost::split(*results, line, boost::is_any_of(sep), boost::token_compress_on);
        }
    };

    const char *const DICT_PATH = "./dict/jieba.dict.utf8";
    const char *const HMM_PATH = "./dict/hmm_model.utf8";
    const char *const USER_DICT_PATH = "./dict/user.dict.utf8";
    const char *const IDF_PATH = "./dict/idf.utf8";
    const char *const STOP_WORD_PATH = "./dict/stop_words.utf8";

    class JiebaUtil
    {
    private:
        static cppjieba::Jieba jieba;

    public:
        static void CutString(const std::string &src, std::vector<std::string> *out)
        {
            jieba.CutForSearch(src, *out);
        }
    };

    //静态成员需要在类外初始化
    cppjieba::Jieba JiebaUtil::jieba(DICT_PATH,HMM_PATH,USER_DICT_PATH,IDF_PATH,STOP_WORD_PATH);

}